import request from "@/utils/request";

const FILE_BASE_URL = "/admin/file";

const FileAPI = {
  /**
   * 上传文件到七牛云
   * @param {File} file 文件对象
   * @param {string} provider 存储提供商，默认为 'qiniu'
   * @returns {Promise<string>} 返回文件的访问URL
   */
  uploadToQiniu(file, provider = 'qiniu') {
    const formData = new FormData();
    formData.append('file', file);
    formData.append('provider', provider);
    
    return request({
      url: `${FILE_BASE_URL}/upload`,
      method: "post",
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
  },

  /**
   * 删除文件
   * @param {string} url 文件URL
   * @param {string} provider 存储提供商，默认为 'qiniu'
   * @returns {Promise}
   */
  deleteFile(url, provider = 'qiniu') {
    return request({
      url: `${FILE_BASE_URL}/delete`,
      method: "post",
      params: {
        url,
        provider
      }
    });
  }
};

export default FileAPI;



